
var easyUi = new Object();
var easyUiButtons;
var linkButtons = new Array();
linkButtons["add"] = {text: '添加',iconCls: 'icon-add',handler: function () {add();},plain:true};
linkButtons["edit"] = {text: '修改',iconCls: 'icon-edit',handler: function () {editfun();},plain:true};
linkButtons["remove"] = {text: '删除',iconCls: 'icon-remove',handler: function () {removefun();},plain:true};
linkButtons["refresh"] = {text: '刷新',iconCls: 'icon-refresh',handler: function () {removefun();},plain:true};
linkButtons["save"] = {text: '保存',iconCls: 'icon-save',handler: function () {save();/*alert(1);*/},plain:true};
linkButtons["info"] = {text: '详情',iconCls: 'icon-info',handler: function () {info();/*alert(1);*/},plain:true};
linkButtons["rest"] = {text: '重置',iconCls: 'icon-save',handler: function () {removefun();},plain:true};

// 按钮源
function getLinkButtons (buttons) {
	
	// 复制一份，不影响原始数据
	var linkButtons_bak = linkButtons;
	var result = new Array();
	for (var i=0;i<buttons.length;i++) {
		
		if (buttons[i].handler!=undefined) {
			
			var handler = buttons[i].handler;
			linkButtons_bak[buttons[i].name].handler=function(){eval(handler+"()");};
		}
		if (buttons[i].text!=undefined ) {
			linkButtons_bak[buttons[i].name].text= buttons[i].text;
		}
		
		result[i]=linkButtons_bak[buttons[i].name];
	}
	return result;
}

// 功能不明确
//easyUi.getButton = function (panel,button,func) {
//	
//	linkButtons[button].handler=func;
//	$('#'+panel).linkbutton(linkButtons[button]);
//};

// datagrid  toolbar use
easyUi.initButton = function (buttons) {
	
	easyUiButtons = getLinkButtons(buttons);
	for (var i in easyUiButtons) {
		var id = 'b_'+easyUiButtons[i].id+i;
		easyUiButtons[i].id = id;
	}
	return easyUiButtons;
};

//panel tool button
easyUi.initButtonBar = function (panel,buttons) {
	$('#'+panel).html("");
	var result = new Array();
	easyUiButtons = getLinkButtons(buttons);

	for (var i in easyUiButtons) {
		var id = 'bb_'+easyUiButtons[i].id+i;
		
		$('#'+panel).html($('#'+panel).html()+'<a id="'+id+'"></a>');
		easyUiButtons[i].id = id;
		result[i]=easyUiButtons[i];
	}
	$.each (result,function (i){
		$('#'+result[i].id).linkbutton(result[i]);
		$('#'+result[i].id).click(eval(result[i].handler));
	});
	return $('#'+panel).html();
};

easyUi.grid = function (page,panel,buttons){

};

// 表单
easyUi.form = function (panel,obj) {
	
	$('#'+panel).panel({
		
		title : undefined,
		iconCls : 'icon-remove',
		collapsible : true,
		minimizable : true,
		maximizable : true,
//				closable : true,
//				collapsed : true,
//				minimized : true,
//				maximized : true,
//				closed : true,
	});	
};

/**
 * 生成参数为obj的panel面板，显现参数panel的内容
 * 待测试
 */
easyUi.defaultPanel = function (panel,obj) {
	if (obj != undefined) {
		$("<div></div>",{ id:'defaultPanel',iconCls:'icon-edit'}).append($("#"+panel).html()).panel(obj);
	}else {
		$("<div></div>",{ id:'defaultPanel',iconCls:'icon-edit'}).append($("#"+panel).html()).panel();
	}
};

// 默认的弹出框，panel 面板显示的内容
easyUi.defaultWindow = function (panel,tit,obj) {
	var title = "新窗口";
	var result = undefined;
	if(tit!=undefined) {
		title=tit;
	}
	if (obj!=undefined) {
		result = $("<div></div>",{ id:'defaultWindow',iconCls:'icon-edit'}).append($("#"+panel).html())
		.window(obj);
	}else {
		result = $("<div></div>",{ id:'defaultWindow',iconCls:'icon-edit'}).append($("#"+panel))
			.window({
				width : 600,
				height : 300,
				modal : true,
				title : title,
				shadow : true,
				minimizable : false,
				collapsible : false,
			});
	}
	return result;
	
};




easyUi.buttonBar = function () {
	
	alert("buttonBar");
};

easyUi.filterBar = function () {
	
	alert("buttonBar");
};





//取出单行数据 
easyUi.datagridGetSelected = function (data,flag){
//	alert("data-->"+data);
	//flag 为true 返回多行 ，false 单行
	var rows = $('#'+data).datagrid('getSelections');
	if (flag) {
		
	}else{
		if (rows.length==0) {
			alert("请先选择一行");
		}else {
			return rows[0];
		}
	}
	return rows;
};


//取出多行数据




